{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "223f9be2",
   "metadata": {},
   "source": [
    "# 常用的几个模块的使用 \n",
    "\n",
    "* datetime \n",
    "* time\n",
    "* help() \n",
    "* range（）函数的使用\n",
    "* ramdom\n",
    "\n",
    "-----------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a3763204",
   "metadata": {},
   "source": [
    "# if else 循环嵌套的使用\n",
    "\n",
    "```\n",
    "if 条件:\n",
    "      if-语句块\n",
    "   \n",
    "   if 条件:\n",
    "      if-语句块\n",
    "   else:\n",
    "      else-语句块\n",
    "   \n",
    "   if 条件：\n",
    "      if-语句块\n",
    "   elif 条件:\n",
    "      elif-语句块\n",
    "   ...\n",
    "   else:\n",
    "      else-语句块\n",
    "   可以进行嵌套。 不要超过3层， 最多5层\n",
    "```\n",
    "\n",
    "-----------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d760e8aa",
   "metadata": {},
   "source": [
    "-------------\n",
    "\n",
    "range()方法\n",
    "\n",
    "-------------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d9781b9d",
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(10):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d680aef0",
   "metadata": {},
   "outputs": [],
   "source": [
    "range(1, 10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b3f134b6",
   "metadata": {},
   "outputs": [],
   "source": [
    "list(range(0, 30, 3))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "64301b93",
   "metadata": {},
   "source": [
    "### for 循环 配合 内置函数range()的使用\n",
    "\n",
    "```\n",
    "案例：\n",
    "from datetime import datetime\n",
    "\n",
    "import random\n",
    "import time\n",
    "\n",
    "odds = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59]\n",
    "\n",
    "# range(5) 将和for循环一起实现 for循环子代码执行的次数（5）\n",
    "for i in range(5):\n",
    "    # right_this_second 当前时间点的秒数\n",
    "    right_this_second = datetime.today().second\n",
    "    if right_this_second in odds:\n",
    "        print(\"该时间为秒为单位的奇数时间.\")\n",
    "    else:\n",
    "        print(\"Not an odd second.\")\n",
    "    # wait_time 等待的时间\n",
    "    wait_time = random.randint(1,5)\n",
    "    time.sleep(wait_time)\n",
    "```\n",
    "\n",
    "-----------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "05d387cf",
   "metadata": {},
   "source": [
    "### datetime的使用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "486e11c5",
   "metadata": {},
   "outputs": [],
   "source": [
    "# datetime 里面的 date 方法\n",
    "datetime.date.today()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "389b175d",
   "metadata": {},
   "outputs": [],
   "source": [
    "# datetime 里面的 date 方法 取出年月日\n",
    "datetime.date.today().day"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "58664b5c",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 得出月份\n",
    "datetime.date.today().month"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4582140e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 得出年份\n",
    "datetime.date.today().year"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "122703ef",
   "metadata": {},
   "outputs": [],
   "source": [
    "# datetime 里面的 datetime 的方法 可以取出年月日时分秒毫秒微妙\n",
    "datetime.datetime.today()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e8c9f1bc",
   "metadata": {},
   "outputs": [],
   "source": [
    "# datetime 中 isoformat 格式化年月日\n",
    "datetime.date.isoformat(datetime.date.today())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7dbaf70e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 国际标准时间\n",
    "time.gmtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "89b9a470",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 本地时间\n",
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "45398b0f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 格式化时间\n",
    "time.strftime(\"%H:%M\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b0cc6131",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 使用time 的 strftime方法 找到 年月日 然后拼接在一起就可以了\n",
    "time.strftime('%Y-%m-%d')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "df1879df",
   "metadata": {},
   "source": [
    "----------\n",
    "\n",
    "random\n",
    "\n",
    "-----------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "56287f5e",
   "metadata": {},
   "outputs": [],
   "source": [
    "random.random()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8dff4f0c",
   "metadata": {},
   "outputs": [],
   "source": [
    "#### 课后项目练习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "b6b675e8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "weekday:Monday\n",
      "快去学习\n"
     ]
    }
   ],
   "source": [
    "today = input(\"weekday:\")\n",
    "if today == \"Saturday\":\n",
    "    print(\"放假\")\n",
    "elif today == \"Sunday\":\n",
    "    condition = input(\"mood:\")\n",
    "    if condition == \"Headache\":\n",
    "        print(\"Recover, then rest.\")\n",
    "    else:\n",
    "        print(\"Rest.\")\n",
    "else:\n",
    "    print(\"快去学习\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ead64e6c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
